*****************************************
* Replication Code for 
* "Are There Social Class Gaps in Nascent Political Ambition? Survey Evidence from the Americas"
* Nicholas Carnes and Noam Lupu
* Code updated 20 September 2024 
*****************************************


use "pooled dataset.dta"

* Footnote 6: empirical claim: The Argentina IADB survey was the only one for which we have data on how long respondents took to answer each question. When we ignored respondents who answered this series of questions in under 20 seconds, the estimate was almost identical (6.4%, versus 6.0% in the full sample). 

gen t6plus = (tsum >=6)
replace t6plus = . if tsum ==.
tab surveycy [aw=wt], sum(t6plus)
tab surveycy [aw=wt] if pra15_t >=20 & pra15_t!=., sum(t6plus)

*** Figure A1 ***

preserve

 label variable tsum "Number of candidate traits (out of 7)"
 label variable surveycy "Survey"

 graph set window fontface "Arial"
 hist tsum if tsum<=7, by(surveycy, note("")) width(.9) frac scheme(s1mono) xscale(r(0(1)7)) xtick(0(1)8)

 restore

*** Table 2: Surveys, sample sizes, and items ***

tab surveycy if consid!=., sum(consid)
tab surveycy if consid!=., sum(tsum)
tab surveycy if consid!=., sum(encourage)
tab surveycy if consid!=., sum(lowincome)
tab surveycy if consid!=., sum(lowwealth)
tab surveycy if consid!=., sum(worker)
tab surveycy if consid!=., sum(female)

*** Figure 1: Nascent ambition, by survey (this code produces the values; see R code to produce figure) ***

tab surveycy [aw=wt] , sum(consideredrun)

preserve

quietly sum consideredrun [aw=wt]
gen country = "Average" if _n==1
gen mean = r(mean) if _n==1
gen ci = 1.96 * (r(sd) / sqrt(r(N))) if _n==1
local i=2

levelsof surveycy, local(ids)
foreach x in "Argentina 2017 (F2F)" "Argentina 2019 (F2F)" "Argentina 2019 (online)" "Bolivia 2019 (F2F)" "Brazil 2019 (online)" "Chile 2019 (online)" "Colombia 2019 (online)" "Mexico 2019 (online)" "US 2019 (online)" "Uruguay 2017 (F2F)" {
	local i = `i' + 1
	quietly sum consideredrun [aw=wt] if surveycy=="`x'"
	replace country ="`x'" if _n==`i'
	replace mean = r(mean) if _n==`i'
	replace ci = 1.96 * (r(sd) / sqrt(r(N))) if _n==`i'
}

keep country mean ci
drop if mean==. & _n!=2

save "figure1.dta", replace
restore


*** Appendix Table A2: Sample demographic comparisons ***

foreach x in "Argentina 2017 (F2F)" "Argentina 2019 (F2F)" "Argentina 2019 (online)" "Bolivia 2019 (F2F)" "Brazil 2019 (online)" "Chile 2019 (online)" "Colombia 2019 (online)" "Mexico 2019 (online)" "US 2019 (online)" "Uruguay 2017 (F2F)" {
	tab female if surveycy=="`x'"
	tab female [aw=wt] if surveycy=="`x'"
	tab agegrp if surveycy=="`x'"
	tab agegrp [aw=wt] if surveycy=="`x'"
	tab educ if surveycy=="`x'"
	tab educ [aw=wt] if surveycy=="`x'"
}

*** Appendix Table A3: Regression models relating potential candidate proxies to economic and gender indicators ***

tab surveycy, gen(survey_)

regress t6plus worker  survey_* [aw=wt], vce(cluster surveycy)
sum t6plus if worker!=. [aw=wt]
regress encourage worker  survey_* [aw=wt], vce(cluster surveycy)
sum encourage if worker!=. [aw=wt]

regress t6plus lowincome  survey_* [aw=wt], vce(cluster surveycy)
sum t6plus if lowincome!=. [aw=wt]
regress encourage lowincome survey_*  [aw=wt], vce(cluster surveycy)
sum encourage if lowincome!=. [aw=wt]

regress t6plus lowwealth  survey_* [aw=wt], vce(cluster surveycy)
sum t6plus if lowwealth!=. [aw=wt]
regress encourage lowwealth  survey_* [aw=wt], vce(cluster surveycy)
sum encourage if lowwealth!=. [aw=wt]

regress t6plus female  survey_* [aw=wt], vce(cluster surveycy)
sum t6plus if female!=. [aw=wt]
regress encourage female  survey_* [aw=wt], vce(cluster surveycy)
sum encourage if female!=. [aw=wt]

*** Footnote 15: "Consistent with the larger literature on politicians from the working class, women were not underrepresented in our less privileged economic categories . . ." 

tab worker female if t6plus==1 [aw=wt], row
tab lowinc female if t6plus==1 [aw=wt], row
tab lowwealth female if t6plus==1 [aw=wt], row

tab worker female if encourage==1 [aw=wt], row
tab lowinc female if encourage==1 [aw=wt], row
tab lowwealth female if encourage==1 [aw=wt], row

*** Appendix Table A4: Regression models relating potential candidate proxies to economic and gender indicators (with country-level controls)

xi: reg  t6plus worker survey_* i.electoralsystem ginidisposable [aw=wt], vce(cluster surveycy)
xi: reg  encourage worker survey_* i.electoralsystem ginidisposable [aw=wt], vce(cluster surveycy)

xi: reg  t6plus lowincome survey_* i.electoralsystem ginidisposable [aw=wt], vce(cluster surveycy)
xi: reg  encourage lowincome survey_* i.electoralsystem ginidisposable [aw=wt], vce(cluster surveycy)

xi: reg  t6plus lowwealth survey_* i.electoralsystem ginidisposable [aw=wt], vce(cluster surveycy)
xi: reg  encourage lowwealth survey_* i.electoralsystem ginidisposable [aw=wt], vce(cluster surveycy)

xi: reg  t6plus female survey_* i.electoralsystem ginidisposable [aw=wt], vce(cluster surveycy)
xi: reg  encourage female survey_* i.electoralsystem ginidisposable [aw=wt], vce(cluster surveycy)

*** Figure 2: Gaps in nascent ambition (this code produces the values; see R code to produce figure), AND ***
*** Appendix Table A5: Regression results summarized in Figure 2 (plus full-sample results referenced parenthetically)***

xi: reg consid worker survey_* [pw=wt] , vce(cluster surveycy)
tab worker if consid!=. 
margins , at(worker==0 worker==1)
xi: reg consid worker survey_* [pw=wt] if t6plus==1, vce(cluster surveycy)
tab worker if consid!=. & t6plus==1
margins , at(worker==0 worker==1)
xi: reg consid worker i.surveycy [pw=wt] if encourage==1, vce(cluster surveycy)
tab worker if consid!=. & encourage==1
margins , at(worker==0 worker==1)

xi: reg consid lowincome survey_* [pw=wt] , vce(cluster surveycy)
tab lowincome if consid!=. 
margins , at(lowincome==0 lowincome==1)
xi: reg consid lowincome i.surveycy [pw=wt] if t6plus==1, vce(cluster surveycy)
tab lowincome if consid!=. & t6plus==1
margins , at(lowincome==0 lowincome==1)
xi: reg consid lowincome i.surveycy [pw=wt] if encourage==1, vce(cluster surveycy)
tab lowincome if consid!=. & encourage==1
margins , at(lowincome==0 lowincome==1)

xi: reg consid lowwealth survey_* [pw=wt] , vce(cluster surveycy)
tab lowwealth if consid!=. 
margins , at(lowwealth==0 lowwealth==1)
xi: reg consid lowwealth i.surveycy [pw=wt] if t6plus==1, vce(cluster surveycy)
tab lowwealth if consid!=. & t6plus==1
margins , at(lowwealth==0 lowwealth==1)
xi: reg consid lowwealth i.surveycy [pw=wt] if encourage==1, vce(cluster surveycy)
tab lowwealth if consid!=. & encourage==1
margins , at(lowwealth==0 lowwealth==1)

xi: reg consid female survey_* [pw=wt] , vce(cluster surveycy)
tab female if consid!=. 
margins , at(female==0 female==1)
xi: reg consid female i.surveycy [pw=wt] if t6plus==1, vce(cluster surveycy)
tab female if consid!=. & t6plus==1
margins , at(female==0 female==1)
xi: reg consid female i.surveycy [pw=wt] if encourage==1, vce(cluster surveycy)
tab female if consid!=. & encourage==1
margins , at(female==0 female==1)


*** Figure A2: Gaps in nascent ambition, varying the cutoff for the number of traits needed to be counted as a potential candidate ***

tab tsum [aw=wt] if consid!=.
tab encourage [aw=wt] if consid!=.

gen group=.
replace group = 1 if _n==1
replace group = 2 if _n==2
replace group = 3 if _n==3
replace group = 4 if _n==4
replace group = 5 if _n==5
replace group = 6 if _n==6

gen work=.
gen lowinc=.
gen lowwea=.
gen fem=.

regress consid worker survey_* [aw=wt] if tsum>=1 & tsum!=., vce(cluster surveycy)
replace work = el(e(b),1,1) if _n==1
regress consid worker survey_* [aw=wt] if tsum>=2 & tsum!=., vce(cluster surveycy)
replace work = el(e(b),1,1) if _n==2
regress consid worker survey_* [aw=wt] if tsum>=3 & tsum!=., vce(cluster surveycy)
replace work = el(e(b),1,1) if _n==3
regress consid worker survey_* [aw=wt] if tsum>=4 & tsum!=., vce(cluster surveycy)
replace work = el(e(b),1,1) if _n==4
regress consid worker survey_* [aw=wt] if tsum>=5 & tsum!=., vce(cluster surveycy)
replace work = el(e(b),1,1) if _n==5
regress consid worker survey_* [aw=wt] if tsum>=6 & tsum!=., vce(cluster surveycy)
replace work = el(e(b),1,1) if _n==6

regress consid lowincome survey_* [aw=wt] if tsum>=1 & tsum!=., vce(cluster surveycy)
replace lowinc = el(e(b),1,1) if _n==1
regress consid lowincome survey_* [aw=wt] if tsum>=2 & tsum!=., vce(cluster surveycy)
replace lowinc = el(e(b),1,1) if _n==2
regress consid lowincome survey_* [aw=wt] if tsum>=3 & tsum!=., vce(cluster surveycy)
replace lowinc = el(e(b),1,1) if _n==3
regress consid lowincome survey_* [aw=wt] if tsum>=4 & tsum!=., vce(cluster surveycy)
replace lowinc = el(e(b),1,1) if _n==4
regress consid lowincome survey_* [aw=wt] if tsum>=5 & tsum!=., vce(cluster surveycy)
replace lowinc = el(e(b),1,1) if _n==5
regress consid lowincome survey_* [aw=wt] if tsum>=6 & tsum!=., vce(cluster surveycy)
replace lowinc = el(e(b),1,1) if _n==6

regress consid lowwealth survey_* [aw=wt] if tsum>=1 & tsum!=., vce(cluster surveycy)
replace lowwea = el(e(b),1,1) if _n==1
regress consid lowwealth survey_* [aw=wt] if tsum>=2 & tsum!=., vce(cluster surveycy)
replace lowwea = el(e(b),1,1) if _n==2
regress consid lowwealth survey_* [aw=wt] if tsum>=3 & tsum!=., vce(cluster surveycy)
replace lowwea = el(e(b),1,1) if _n==3
regress consid lowwealth survey_* [aw=wt] if tsum>=4 & tsum!=., vce(cluster surveycy)
replace lowwea = el(e(b),1,1) if _n==4
regress consid lowwealth survey_* [aw=wt] if tsum>=5 & tsum!=., vce(cluster surveycy)
replace lowwea = el(e(b),1,1) if _n==5
regress consid lowwealth survey_* [aw=wt] if tsum>=6 & tsum!=., vce(cluster surveycy)
replace lowwea = el(e(b),1,1) if _n==6

regress consid female survey_* [aw=wt] if tsum>=1 & tsum!=., vce(cluster surveycy)
replace fem = el(e(b),1,1) if _n==1
regress consid female survey_* [aw=wt] if tsum>=2 & tsum!=., vce(cluster surveycy)
replace fem = el(e(b),1,1) if _n==2
regress consid female survey_* [aw=wt] if tsum>=3 & tsum!=., vce(cluster surveycy)
replace fem = el(e(b),1,1) if _n==3
regress consid female survey_* [aw=wt] if tsum>=4 & tsum!=., vce(cluster surveycy)
replace fem = el(e(b),1,1) if _n==4
regress consid female survey_* [aw=wt] if tsum>=5 & tsum!=., vce(cluster surveycy)
replace fem = el(e(b),1,1) if _n==5
regress consid female survey_* [aw=wt] if tsum>=6 & tsum!=., vce(cluster surveycy)
replace fem = el(e(b),1,1) if _n==6

preserve
keep group work lowinc lowwea fem
drop if group==.
save "figurea2.dta", replace
restore

drop group work lowinc lowwea fem


*** Footnote 16: Estimating gender gap using white-collar professionals as our proxy for potential candidates ***

regress consideredrun female survey_* [aw=wt] if worker==0, vce(cluster surveycy)

*** Paragraph that begins, "Our findings suggest that the gender gap " ***

gen femworker = 0 if female!=. & worker!=.
replace femworker = 1 if female==1 & worke==1
gen femprof = 0 if female!=. & worker!=.
replace femprof = 1 if female==1 & worke==0
gen maleworker = 0 if female!=. & worker!=.
replace maleworker = 1 if female==0 & worke==1

gen femlowinc = 0 if female!=. & lowinc!=.
replace femlowinc = 1 if female==1 & lowinc==1
gen femhighinc = 0 if female!=. & lowinc!=.
replace femhighinc = 1 if female==1 & lowinc==0
gen malelowinc = 0 if female!=. & lowinc!=.
replace malelowinc = 1 if female==0 & lowinc==1

gen femlowwealth = 0 if female!=. & lowwealth!=.
replace femlowwealth = 1 if female==1 & lowwealth==1
gen femhighwealth = 0 if female!=. & lowwealth!=.
replace femhighwealth = 1 if female==1 & lowwealth==0
gen malelowwealth = 0 if female!=. & lowwealth!=.
replace malelowwealth = 1 if female==0 & lowwealth==1

regress consid femworker femprof maleworker survey_* [aw=wt] if t6plus==1, vce(cluster surveycy)
regress consid femlowinc femhighinc malelowinc survey_* [aw=wt] if t6plus==1, vce(cluster surveycy)
regress consid femlowwealth femhighwealth malelowwealth survey_* [aw=wt] if t6plus==1, vce(cluster surveycy)

*** Footnote 18: "The results were substantively similar when we used the encouragement proxy instead of the candidate trait proxy to identify potential candidates."

regress consid femworker femprof maleworker survey_* [aw=wt] if encourage==1, vce(cluster surveycy)
regress consid femlowinc femhighinc malelowinc survey_* [aw=wt] if encourage==1, vce(cluster surveycy)
regress consid femlowwealth femhighwealth malelowwealth survey_* [aw=wt] if encourage==1, vce(cluster surveycy)

*** Table 3: Percentage-point gaps in nascent ambition, by survey, AND ***
*** Table A6: Regression results summarized in Table 3 ***

regress consid worker [aw=wt] if tsum>=6 & tsum!=. & surveycy=="Argentina 2019 (F2F)"
regress consid worker [aw=wt] if tsum>=6 & tsum!=. & surveycy=="Bolivia 2019 (F2F)"
regress consid worker [aw=wt] if tsum>=6 & tsum!=. & surveycy=="Chile 2019 (online)"

regress consid lowincome [aw=wt] if tsum>=6& tsum!=. & surveycy=="Argentina 2019 (online)"
regress consid lowincome [aw=wt] if tsum>=6& tsum!=. & surveycy=="Argentina 2019 (F2F)"
regress consid lowincome [aw=wt] if tsum>=6& tsum!=. & surveycy=="Bolivia 2019 (F2F)"
regress consid lowincome [aw=wt] if tsum>=6& tsum!=. & surveycy=="Brazil 2019 (online)"
regress consid lowincome [aw=wt] if tsum>=6& tsum!=. & surveycy=="Colombia 2019 (online)"
regress consid lowincome [aw=wt] if tsum>=6& tsum!=. & surveycy=="Mexico 2019 (online)"
regress consid lowincome [aw=wt] if tsum>=6& tsum!=. & surveycy=="US 2019 (online)"

regress consid lowwealth [aw=wt] if tsum>=6& tsum!=. & surveycy=="Argentina 2019 (F2F)"
regress consid lowwealth [aw=wt] if tsum>=6& tsum!=. & surveycy=="Bolivia 2019 (F2F)"

regress consid female [aw=wt] if tsum>=6& tsum!=. & surveycy=="Argentina 2019 (online)"
regress consid female [aw=wt] if tsum>=6& tsum!=. & surveycy=="Argentina 2019 (F2F)"
regress consid female [aw=wt] if tsum>=6& tsum!=. & surveycy=="Bolivia 2019 (F2F)"
regress consid female [aw=wt] if tsum>=6& tsum!=. & surveycy=="Brazil 2019 (online)"
regress consid female [aw=wt] if tsum>=6& tsum!=. & surveycy=="Chile 2019 (online)"
regress consid female [aw=wt] if tsum>=6& tsum!=. & surveycy=="Colombia 2019 (online)"
regress consid female [aw=wt] if tsum>=6& tsum!=. & surveycy=="Mexico 2019 (online)"
regress consid female [aw=wt] if tsum>=6& tsum!=. & surveycy=="US 2019 (online)"

regress consid worker [aw=wt] if encourage==1& surveycy=="Argentina 2019 (F2F)"
regress consid worker [aw=wt] if encourage==1& surveycy=="Bolivia 2019 (F2F)"

regress consid lowincome [aw=wt] if encourage==1& surveycy=="Argentina 2017 (F2F)"
regress consid lowincome [aw=wt] if encourage==1& surveycy=="Argentina 2019 (F2F)"
regress consid lowincome [aw=wt] if encourage==1& surveycy=="Bolivia 2019 (F2F)"
regress consid lowincome [aw=wt] if encourage==1& surveycy=="Colombia 2019 (online)"
regress consid lowincome [aw=wt] if encourage==1& surveycy=="Mexico 2019 (online)"
regress consid lowincome [aw=wt] if encourage==1& surveycy=="Uruguay 2017 (F2F)"

regress consid lowwealth [aw=wt] if encourage==1& surveycy=="Argentina 2017 (F2F)"
regress consid lowwealth [aw=wt] if encourage==1& surveycy=="Argentina 2019 (F2F)"
regress consid lowwealth [aw=wt] if encourage==1& surveycy=="Bolivia 2019 (F2F)"
regress consid lowwealth [aw=wt] if encourage==1& surveycy=="Uruguay 2017 (F2F)"

regress consid female [aw=wt] if encourage==1& surveycy=="Argentina 2017 (F2F)"
regress consid female [aw=wt] if encourage==1& surveycy=="Argentina 2019 (F2F)"
regress consid female [aw=wt] if encourage==1& surveycy=="Bolivia 2019 (F2F)"
regress consid female [aw=wt] if encourage==1& surveycy=="Colombia 2019 (online)"
regress consid female [aw=wt] if encourage==1& surveycy=="Mexico 2019 (online)"
regress consid female [aw=wt] if encourage==1& surveycy=="Uruguay 2017 (F2F)"

*** Figure A3: Gaps in nascent ambition (with added controls for education) ***

xi: reg consid worker i.educ survey_* [pw=wt] if t6plus==1, vce(cluster surveycy)
tab worker if consid!=. & t6plus==1
margins , at(worker==0 worker==1)
xi: reg consid worker i.surveycy i.educ [pw=wt] if encourage==1, vce(cluster surveycy)
tab worker if consid!=. & encourage==1
margins , at(worker==0 worker==1)

xi: reg consid lowincome i.educ i.surveycy [pw=wt] if t6plus==1, vce(cluster surveycy)
tab lowincome if consid!=. & t6plus==1
margins , at(lowincome==0 lowincome==1)
xi: reg consid lowincome i.educ i.surveycy [pw=wt] if encourage==1, vce(cluster surveycy)
tab lowincome if consid!=. & encourage==1
margins , at(lowincome==0 lowincome==1)

xi: reg consid lowwealth i.educ i.surveycy [pw=wt] if t6plus==1, vce(cluster surveycy)
tab lowwealth if consid!=. & t6plus==1
margins , at(lowwealth==0 lowwealth==1)
xi: reg consid lowwealth i.educ i.surveycy [pw=wt] if encourage==1, vce(cluster surveycy)
tab lowwealth if consid!=. & encourage==1
margins , at(lowwealth==0 lowwealth==1)

xi: reg consid female i.educ i.surveycy [pw=wt] if t6plus==1, vce(cluster surveycy)
tab female if consid!=. & t6plus==1
margins , at(female==0 female==1)
xi: reg consid female i.educ i.surveycy [pw=wt] if encourage==1, vce(cluster surveycy)
tab female if consid!=. & encourage==1
margins , at(female==0 female==1)

*** Table A8: Gaps in nascent ambition (with country-level controls)

xi: reg consid worker survey_* i.electoralsystem ginidisposable [pw=wt] , vce(cluster surveycy)
xi: reg consid worker survey_* i.electoralsystem ginidisposable [pw=wt] if t6plus==1, vce(cluster surveycy)
xi: reg consid worker i.surveycy i.electoralsystem ginidisposable [pw=wt] if encourage==1, vce(cluster surveycy)

xi: reg consid lowincome survey_* i.electoralsystem ginidisposable [pw=wt] , vce(cluster surveycy)
xi: reg consid lowincome i.surveycy i.electoralsystem ginidisposable [pw=wt] if t6plus==1, vce(cluster surveycy)
xi: reg consid lowincome i.surveycy i.electoralsystem ginidisposable [pw=wt] if encourage==1, vce(cluster surveycy)

xi: reg consid lowwealth survey_* i.electoralsystem ginidisposable [pw=wt] , vce(cluster surveycy)
xi: reg consid lowwealth i.surveycy i.electoralsystem ginidisposable [pw=wt] if t6plus==1, vce(cluster surveycy)
xi: reg consid lowwealth i.surveycy i.electoralsystem ginidisposable [pw=wt] if encourage==1, vce(cluster surveycy)

xi: reg consid female survey_* i.electoralsystem ginidisposable [pw=wt] , vce(cluster surveycy)
xi: reg consid female i.surveycy i.electoralsystem ginidisposable [pw=wt] if t6plus==1, vce(cluster surveycy)
xi: reg consid female i.surveycy i.electoralsystem ginidisposable [pw=wt] if encourage==1, vce(cluster surveycy)
 
*** Table A9: Inequality, electoral systems, and nascent ambition ***

xi: reg consid ginidisposable i.electoralsystem [pw=wt] if worker==1 & (tsum==6 | tsum==7), vce(cluster surveycy)
xi: reg consid ginidisposable i.electoralsystem [pw=wt] if worker==0 & (tsum==6 | tsum==7), vce(cluster surveycy)
xi: reg consid ginidisposable i.electoralsystem [pw=wt] if lowincome==1 & (tsum==6 | tsum==7), vce(cluster surveycy)
xi: reg consid ginidisposable i.electoralsystem [pw=wt] if lowincome==0 & (tsum==6 | tsum==7), vce(cluster surveycy)
xi: reg consid ginidisposable i.electoralsystem [pw=wt] if lowwealth==1 & (tsum==6 | tsum==7), vce(cluster surveycy)
xi: reg consid ginidisposable i.electoralsystem [pw=wt] if lowwealth==0 & (tsum==6 | tsum==7), vce(cluster surveycy)
 

*** Figure A4: Distributions of politician attribute question counts (out of seven), by economic measures ***

 graph set window fontface "Arial"
 hist tsum if tsum<=7 , by(worker, note("")) width(.9) frac scheme(s1mono) xscale(r(0(1)7)) xtick(0(1)8)
 hist tsum if tsum<=7 , by(lowincome, note("")) width(.9) frac scheme(s1mono) xscale(r(0(1)7)) xtick(0(1)8)
 hist tsum if tsum<=7 , by(lowwealth, note("")) width(.9) frac scheme(s1mono) xscale(r(0(1)7)) xtick(0(1)8)

